﻿namespace SLClient.Extension
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;

    public class CustomerSlider : Slider
    {
        protected override void OnValueChanged(double oldValue, double newValue)
        {
            int num = Convert.ToInt32(Math.Round(newValue));
            Thumb templateChild = base.GetTemplateChild("HorizontalThumb") as Thumb;
            double num2 = base.Maximum;
            double num3 = base.Minimum;
            double num4 = num;
            double num5 = 1.0 - ((num2 - num4) / (num2 - num3));
            RepeatButton button = base.GetTemplateChild("HorizontalTrackLargeChangeDecreaseRepeatButton") as RepeatButton;
            RepeatButton button2 = base.GetTemplateChild("HorizontalTrackLargeChangeIncreaseRepeatButton") as RepeatButton;
            Grid grid = base.GetTemplateChild("HorizontalTemplate") as Grid;
            if (grid != null)
            {
                if ((grid.ColumnDefinitions != null) && (grid.ColumnDefinitions.Count == 3))
                {
                    grid.ColumnDefinitions[0].Width = new GridLength(1.0, GridUnitType.Auto);
                    grid.ColumnDefinitions[2].Width = new GridLength(1.0, GridUnitType.Star);
                    if (button != null)
                    {
                        button.SetValue(Grid.ColumnProperty, 0);
                    }
                    if (button2 != null)
                    {
                        button2.SetValue(Grid.ColumnProperty, 2);
                    }
                }
                if ((button != null) && (templateChild != null))
                {
                    button.Width = Math.Max((double)0.0, (double)(num5 * (base.ActualWidth - templateChild.ActualWidth)));
                }
            }
        }
    }
}

